home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
tutor
/
pro12
/
instr.bas
< prev
next >
Wrap
BASIC Source File
|
1990-10-15
|
2KB
|
54 lines
10 'INSTR.BAS - Demonstration program to demonstrate!the use of the INSTR
20 'function
30 '
40 'From the GW-BASIC Tutorial Series (GWBT05, 10/15/1990)
50 '
60 'The program will use the following variables:
70 '
80 'INPUTSTRING$ is the string the user provides
90 'SEARCHSTRING$ is the string we want to search for
100 'POSITION is the current search position
110 '
120 'What we will do is start at POSITION = 1, and search through the INPUT-
130 'STRING$ for ALL the times that SEARCHSTRING$ can be found, and report
140 'the position each time.
150 '
160 'Start of main program:
170 KEY OFF
180 CLS
190 PRINT "INSTR.BAS - INSTR Demonstration Program"
200 PRINT
210 PRINT "First, I need the string you want to search inside of. Enter a"
220 PRINT "sentence, group of words, etc. Press ENTER alone to quit."
230 LINE INPUT "Your string =>";INPUTSTRING$
240 IF INPUTSTRING$="" THEN END
250 PRINT
260 PRINT "Next, I need the string you want to LOOK FOR inside the first"
270 PRINT "string. This may be a letter, space, word, etc."
280 PRINT
290 LINE INPUT "Search string =>";SEARCHSTRING$
300 '
310 'We have both strings, now start searching...
320 '
330 POSITION = 1
340 LOCATION=INSTR(POSITION,INPUTSTRING$,SEARCHSTRING$)
350 '
360 'If it is found, LOCATION will be greater than zero. If it cannot be found
370 'then LOCATION will be zero.
380 IF LOCATION > 0 THEN GOTO 430
390 PRINT "No further matches found. Press any key to try new strings..."
400 WHILE INKEY$="":WEND
410 GOTO 180
420 '
430 'Match found, now tell where it was
440 '
450 PRINT "A match was found at position ";LOCATION
460 '
470 'Now add 1 to the current location, make this the start position, and look
480 'again for any more locations of the search string...
490 '
500 POSITION=LOCATION + 1
510 GOTO 340
520 END
530 'End of program - INSTR.BAS